package com.enqualcomm.kids.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.enqualcomm.kids.R;

import common.utils.DensityUtil;

/**
 * Created by Sunzhigang on 2016/7/26.
 */
public class ChooseCountryCodeDialog extends Dialog {
    private onCountryCodeChoosedListener callBack;
    private Context context;

    public ChooseCountryCodeDialog(Context context, onCountryCodeChoosedListener callBack) {
        super(context);
        this.callBack = callBack;
        this.context = context;
    }

    public ChooseCountryCodeDialog(Context context, int themeResId) {
        super(context, themeResId);
    }

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.country_code_dialog);

        setDialogAttributes();
        initDialogView();
    }

    public void setDialogAttributes() {
        Window dialogWindow = getWindow();
        dialogWindow.setGravity(Gravity.CENTER);
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();

        DisplayMetrics dm = new DisplayMetrics();
        dialogWindow.getWindowManager().getDefaultDisplay().getMetrics(dm);

        lp.width = dm.widthPixels - DensityUtil.dip2px(getContext(), 30); // 宽度
        // lp.alpha = 0.9f; // 透明度

        dialogWindow.setAttributes(lp);
        dialogWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    }

    public void initDialogView() {
        findViewById(R.id.china_rl).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (callBack != null) {
                    callBack.choosed("+86");
                }
                dismiss();
            }
        });
        findViewById(R.id.hk_rl).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (callBack != null) {
                    callBack.choosed("+852");
                }
                dismiss();
            }
        });
        findViewById(R.id.am_rl).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (callBack != null) {
                    callBack.choosed("+853");
                }
                dismiss();
            }
        });
        findViewById(R.id.tw_rl).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (callBack != null) {
                    callBack.choosed("+886");
                }
                dismiss();
            }
        });
        findViewById(R.id.reset_rl).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (callBack != null) {
                    callBack.choosed(context.getString(R.string.watch_numer_country_regin));
                }
                dismiss();
            }
        });
    }
}
